package com.linkgie.galaxyframework.utils;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 长整数计数器；
 * <p>
 * 
 * 此实现不是线程安全的；
 * <p>
 * 在需要线程安全的场景时，推荐使用 {@link AtomicLong } ；
 */
public class LongCounter {

    private long count;

    /**
     * @param initialValue
     */
    public LongCounter() {
        this.count = 0;
    }

    /**
     * @param initialValue
     */
    public LongCounter(long initialValue) {
        this.count = initialValue;
    }

    public void set(long value){
        this.count = value;
    }

    public long increase(){
        return ++count;
    }

    public long increase(long increment){
        count = count + increment;
        return count;
    }

    public long decrease(){
        return --count;
    }

    public long decrease(long decrement){
        count = count - decrement;
        return count;
    }

    public long value(){
        return count;
    }

}
